package com.team24.hotel.controller;

import com.team24.hotel.domain.City;
import com.team24.hotel.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/city")
public class CityController {

    @Autowired
    private CityService cityService;

    @RequestMapping("/getAll")
    public String getAllCityAndProvince(Model model){
        List<City> cityList=cityService.findAllCityAndProvinceName();
        model.addAttribute("cityList",cityList);
        return "cityList";
    }

    @RequestMapping("/getSome")
    @ResponseBody
    public List<City> getSomeByProvinceId(String provinceId) {
        List<City> cities=cityService.findAllByProvinceId(Integer.parseInt(provinceId));
        return cities;
    }

}
